package com.hzf.common.util;

import com.hzf.common.ShalUtil;

import java.util.Arrays;

public class WeixinUtils {

    //微信公众平台登录的签名校验
    private static final String token="tmZ37D12me3tk2AUzntq07QN44D2N6q2";

    public static boolean checkSignature(String signature,String timestamp,String nonce) {
        //1、排序
        String [] arr = new String[]{token,timestamp,nonce};
        Arrays.sort(arr);
        //2、生成新的字符串
        StringBuffer content = new StringBuffer();
        for(int i=0;i<arr.length;i++){
            content.append(arr[i]);
        }
        //3、shal加密
        String temp = ShalUtil.getSha1(content.toString());
        return temp.equals(signature);
    }
}
